import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class SearchAsin {
	private long id;
	private long item_no;
	private String asin_temp;
	private long numberProducts;

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public long getItem_no() {
		return item_no;
	}

	public void setItem_no(long item_no) {
		this.item_no = item_no;
	}

	public String getAsin_temp() {
		return asin_temp;
	}

	public void setAsin_temp(String asin_temp) {
		this.asin_temp = asin_temp;
	}

	public long getNumberProducts() {
		return numberProducts;
	}

	public void setNumberProducts(long numberProducts) {
		this.numberProducts = numberProducts;
	}
	
	
	public static List<SearchAsin> getSearchAsins(Connection connection) throws SQLException{
		List<SearchAsin> asins = new ArrayList<SearchAsin>();
		ResultSet rs= connection.createStatement().executeQuery("select id,asin_temp,item_no from search_asin where completed=0");
		while (rs.next()) {
			SearchAsin searchAsin = new SearchAsin();
			searchAsin.setId(rs.getLong(1));
			searchAsin.setAsin_temp(rs.getString(2));
			searchAsin.setItem_no(rs.getLong(3));
			asins.add(searchAsin);
		}
		
		return asins;
		
	}
    public static int upDateSearchAsins(Connection connection,SearchAsin searchAsin) throws SQLException{
    	String sql="update search_asin set numberProducts="+searchAsin.getNumberProducts()+" where id="+searchAsin.getId();
    	int rs= connection.createStatement().executeUpdate(sql);
    	connection.commit();
    	return rs;
    	
    }
}
